/**
 * Created by hoter.zhang on 2017/9/12.
 */
import React, {Component} from 'react'
import {Card} from 'antd'
import { Link } from 'react-router-dom'

export default class PCNewsBlock extends Component {
    constructor() {
        super();
        this.state = {
            news: ''
        }
    }

    componentWillMount() {
        var myFetchOptions = {
            method: 'GET',
        }
        fetch("http://newsapi.gugujiankong.com/Handler.ashx?action=getnews&type=" + this.props.type + "&count=" + this.props.count, myFetchOptions)
            .then(resoponse=>resoponse.json())
            .then(json=>this.setState({
                news: json
            }))
    }

    render() {
        const {news} = this.state;
        console.log(news);
        const newsList = news.length
                ?
                news.map((newsItem, index) => (
                    <li key={index}>
                        {newsItem.title}
                    </li>
                ))
                :
                '沒有任何數據'
            ;
        return (
            <div className="topNewsList">
                <Card>
                    <ul>
                        {newsList}
                    </ul>
                </Card>
            </div>
        )
    }
}